//
//  Stack.m
//  xmldemo
//
//  Created by fangdi on 09-9-14.
//  Copyright 2009 __MyCompanyName__. All rights reserved.
//

#import "Stack.h"

@implementation Stack

-(id)init{
	if((self = [super init]) != nil){
		array = [[NSMutableArray alloc] init];
		return self;
	}
	return nil;
}

-(NSObject *)getFirst{
	if([self isEmpty]){
		return nil;
	}
	return [array objectAtIndex:headIndex];
}

-(NSObject *)pop{
	if([self isEmpty]){
		return nil;
	}
	return [array objectAtIndex:headIndex++];
}

-(NSObject *)getLast{
	if([self isEmpty]){
		return nil;
	}
	return [array objectAtIndex:(tailIndex - 1)];
}

-(void)push: (NSObject *) obj{
	[array addObject:obj];
	tailIndex++;
}

-(BOOL)isEmpty{
	return tailIndex == headIndex;
}

-(void)dealloc{
	[array release];
	[super dealloc];
}
@end
